using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using TDUpdate;
using TDDraw;
using TDDraw.Input;
using System.Collections.Specialized;

namespace TD
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class TD : Game
    {
        GraphicsDeviceManager graphics;                

        public TD()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "TDContent";

            // Adjust windows size
            graphics.PreferredBackBufferHeight = 768;
            graphics.PreferredBackBufferWidth = 1024;
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            UpdateManager.UpdateComponentList.Changed += new EventHandler<UpdateComponentCollectionChangedEventArgs>(DrawManager.UpdateComponentList_Changed);
            UpdateManager.Mouse = MouseManager.Instance;

            TextureManager.Instance.Game = this;

            DrawManager.TileHeight = 20;
            DrawManager.TileWidth = 20;

            DrawManager.ScreenHeight = graphics.PreferredBackBufferHeight;
            DrawManager.ScreenWidth = graphics.PreferredBackBufferWidth;
            DrawManager.GraphicsDevice = GraphicsDevice;

            this.IsMouseVisible = true; // Deaktivieren sobald die grafische Maus portiert wurde

            base.Initialize();
        }

        protected override void LoadContent()
        {
            DrawManager.DefaultSpriteBatch = new SpriteBatch(GraphicsDevice);
            UpdateManager.Start();

            base.LoadContent();
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            InputManager.UpdateInput(gameTime);

            UpdateManager.Update(gameTime);

            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            DrawManager.Draw(gameTime);

            base.Draw(gameTime);
        }
    }
}
